WATER WORLD
the landscape is 16 columns wide. read the input 16 times to get the height of the landscape at each column from left to right. then output the total colume that the landscape can carry as the answer.
風景は16列幅です。入力を16回読み取り、各列の風景の高さを左から右に取得します。次に、風景が運ぶことができる合計列を答えとして出力します。
https://gyazo.com/3698bb4a9d2253b0a940423141da092d
https://gyazo.com/61c7b006ff74189d4cdfd4edb0d49a34
アルゴリズム
https://gyazo.com/55acaf9bd3790dcbb1f69bd12d14e3b1
code:water_world
const add 0
const add_ri 64
const add_ii 192
const sub 1
const sub_ri 65
const sub_ir 129
const jeq 32
const jeq_ri 96
const jeq_ii 224
const jlt 34
const jlte 35
const jgt 36
const jgte 37
const jgte_ri 101
const sw 16
const sw_ri 80
const lw 17
const lw_ri 81
const call 8
const ret 9
const r0 0
const r1 1
const r2 2
const r3 3
const r4 4
const r5 5
const sp 5
const sp_offset 4
const counter 6
const input 7
const output 7
const _ 0
const i 1
const val 2
const max 3
const edge 3
const j 4
const LEFT_MAX 16
const RIGHT_MAX 32
const EDGE 48
const WATER 64
add_ii 0 _ i
label load_height
jeq_ri i 16 end_load_height
add input _ val
sw i _ val
add_ri i 1 i
jeq _ _ load_height
label end_load_height
add_ii 0 _ i
add_ii 0 _ max
label calc_highest_from_left
jeq_ri i 16 end_calc_highest_from_left
lw i _ val
jlt val max _skip_update_left_max
add val _ max
label _skip_update_left_max
sw_ri i LEFT_MAX max
add_ri i 1 i
jeq _ _ calc_highest_from_left
label end_calc_highest_from_left
add_ii 0 _ i
add_ii 0 _ max
label calc_highest_from_right
jeq_ri i 16 end_calc_highest_from_right
sub_ir 15 i j
lw j _ val
jlt val max _skip_update_right_max
add val _ max
label _skip_update_right_max
sw_ri j RIGHT_MAX max
add_ri i 1 i
jeq _ _ calc_highest_from_right
label end_calc_highest_from_right
const edge 3
const l_max 4
const r_max 5
add_ii 0 _ i
add_ii 0 _ edge
label calc_edge
jeq_ri i 16 end_calc_edge
lw_ri i LEFT_MAX l_max
lw_ri i RIGHT_MAX r_max
jgt l_max r_max edge_is_right
sw_ri i EDGE l_max
jeq _ _ foo
label edge_is_right
sw_ri i EDGE r_max
label foo
add_ri i 1 i
jeq _ _ calc_edge
label end_calc_edge
const edge 3
const bottom 4
const v 5
add_ii 0 _ i
label calc_water
jeq_ri i 16 end_calc_water
lw_ri i EDGE edge
lw_ri i _ bottom
sub edge bottom v
jlt v r0 bar
sw_ri i WATER v
label bar
add_ri i 1 i
jeq _ _ calc_water
label end_calc_water
const sum 5
add_ii 0 _ i
add_ii 0 _ sum
label sum
jeq_ri i 16 end_sum
lw_ri i WATER v
add sum v sum
add_ri i 1 i
jeq _ _ sum
label end_sum
add sum _ output